﻿@{
    Layout = "~/Views/Shared/_FormWhite.cshtml";
}

<div class="wrapper animated fadeInRight">
    <form id="form" class="form-horizontal m">
        <div class="form-group">
            <label class="col-sm-3 control-label ">租户姓名<font class="red"> *</font></label>
            <div class="col-sm-8">
                <input id="name" col="name" type="text" class="form-control" />
            </div>
        </div>
        @*<div class="form-group">
            <label class="col-sm-3 control-label ">账号<font class="red"> *</font></label>
            <div class="col-sm-8" id="contact_user_id" col="contact_user_id" >

            </div>
        </div>*@
        <div class="form-group">
            <label class="col-sm-3 control-label ">联系电话<font class="red">*</font></label>
            <div class="col-sm-8">
                <input id="contact_mobile" col="contact_mobile" type="text" class="form-control" />
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label ">租户类型<font class="red">*</font></label>
            <div class="col-sm-8" id="type" col="type">

            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label ">状态<font class="red"> *</font></label>
            <div class="col-sm-8" id="status" col="status">

            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label ">到期时间</label>
            <div class="col-sm-8">
                <input id="expire_time" col="expire_time" type="text" class="form-control" />
            </div>
        </div>
    </form>
</div>

<script type="text/javascript">
    var id = ys.request("id");
    $(function () {

        $("#type").ysRadioBox({ data: ys.getJson(@Html.Raw(typeof(SysTenantTypeEnum).EnumToDictionaryString())) });

        $("#status").ysRadioBox({ data: ys.getJson(@Html.Raw(typeof(SysTenantEnum).EnumToDictionaryString())) });

        @*$("#contact_user_id").ysComboBox({
            url: '@Url.Content("~/OrganizationManage/SysTenant/GetCustomerPageListJson")',
            key: "Id",
            value: "UserName",
            class: "form-control",
        });*@

        // 绑定点击事件
        $("#type input[type='radio']").on('ifClicked', function(event) {
            var value = $(this).val();
            if (value ==2) {
                $("#expire_time").parent().parent().show();
            }
            else { 
                $("#expire_time").parent().parent().hide();
            }
        });

        laydate.render({ elem: '#expire_time', type: 'datetime', format: 'yyyy-MM-dd HH:mm:ss' });

        getForm();

        $('#form').validate({
            rules: {
                name: { required: true },
                contact_user_id_select: { required: true }
            }
        });
    });

    

    function getForm() {
        if (id > 0) {
            ys.ajax({
                url: '@Url.Content("~/OrganizationManage/SysTenant/GetFormJson")' + '?id=' + id,
                type: 'get',
                success: function (obj) {
                    if (obj.Tag == 1) {
                        if (obj.Data.type == 1) {
                            $("#expire_time").parent().parent().hide();
                        }
                        else
                        {
                            $("#expire_time").parent().parent().show();
                        }
                        $('#form').setWebControls(obj.Data);
                    }
                }
            });
        }
        else {
            var defaultData = {};
            defaultData.type = "@SysTenantTypeEnum.合约.ParseToInt()";
            defaultData.status="@SysTenantEnum.正常.ParseToInt()";
            $('#form').setWebControls(defaultData);
        }
    }

    function saveForm(index) {
        if ($('#form').validate().form()) {
            var postData = $('#form').getWebControls({ Id: id });
            ys.ajax({
                url: '@Url.Content("~/OrganizationManage/SysTenant/SaveFormJson")',
                type: 'post',
                data: postData,
                success: function (obj) {
                    if (obj.Tag == 1) {
                        ys.msgSuccess(obj.Message);
                        parent.searchGrid();
                        parent.layer.close(index);
                    }
                    else {
                        ys.msgError(obj.Message);
                    }
                }
            });
        }
    }
</script>

